JS is client side scripting language, which is used to communicate with HTML elements.

There are two predefined objects in JS -
a) "window" (browser with toolbar + status bar + navigation bar)
b) "document" (visible HTML area on window is document) a.k.a => DOM(Document Object Model)

Events in JS :-

a) onClick()
b) onBlur()
c) onChange()
d) onSubmit()

Q. How to include javascript file on html page ?// Off Page Javascript
A. <script type="text/javascript" src="js/site.js"></script>

Q. How to write Javascript code on HTML page ? // On Page Javascript
A. <script type="text/javascript">
   // My javascript Code
   </script>

Q. How to define variable in javascript ?
A. use var keyword..

   var number = 1234;
   var flag = false;


Q. How to add comment in javascript ?
A. Use C style comment

   // Single line comment

   /*
     Multiline comment
     Multiline comment
   */


Q. How to concatenate two strings in javascript?
A. Use (+) plus operator.
   Ex :
   var str;
   str = 'hello' + 'world';
   alert(str); // Helloworld

NOTE : In javascript semicolon is optional at the end of statement.
But for better programming practice we have to use semicolon at end of statement.

Q. Ways to show output on browser with javacript ?
A.
   1) alert("This is alert message"); 
   // popup with OK button
   2) document.write("This message print on web page without alert");
   3) confirm("Are you sure you want to delete ?");
   // popup with OK and CANCEL buttons.
   4) console.log("Used to log message in firebug, press F12 to see that message");

EVENTS :-
=> onBlur="alert(this.value)"
   out of Focus from input element is known as blur()

=> What is focus ?
   Where cursor blinks..

=> onChange="alert(this.value)"
   It is almost same as onBlur, but it will call when there is some change of value in input field.

Q. How to call external function of javascript with any Event ?
A.

<label><input onClick="myFunction(this.value)" required="" type="radio" value="m" name="gender">Male</label>

    <script type="text/javascript">
      function myFunction(val)
      {
        alert(val);// m (m is value of male)
      }
    </script>























